package com.bckj.fastboot.upms.biz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bckj.fastboot.core.lang.model.PageResult;
import com.bckj.fastboot.core.page.PageSupport;
import com.bckj.fastboot.security.annotation.HasPermission;
import com.bckj.fastboot.upms.api.dto.SysRoleQuery;
import com.bckj.fastboot.upms.api.dto.SysRoleRequest;
import com.bckj.fastboot.upms.api.service.SysRoleRemoteService;
import com.bckj.fastboot.upms.api.vo.SysRoleVO;
import com.bckj.fastboot.upms.biz.service.SysRoleService;
import org.springframework.web.bind.annotation.*;


import lombok.RequiredArgsConstructor;
import java.util.List;


/**
 * 角色表(SysRole)表控制层
 *
 * @author wfc
 * @since 2023-09-14 10:12:51
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("sysRole")
public class SysRoleController implements SysRoleRemoteService {
    /**
     * 服务
     */
	private final SysRoleService sysRoleService;
	
    /**
	 * 列表
	 *
	 * @param query req
	 * @return list
	 */
    @Override
	@HasPermission("sys_role")
	@GetMapping("page")
	public PageResult<SysRoleVO> page(SysRoleQuery query) {
		IPage<SysRoleVO> page = PageSupport.page(() -> sysRoleService.list(query));
		return PageResult.of(page);
	}
	
    /**
	 * 列表
	 *
	 * @param query req
	 * @return list
	 */
    @Override
	@GetMapping("list")
	public List<SysRoleVO> list(SysRoleQuery query) {
		return sysRoleService.list(query);
	}

	/**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
	@Override
	@PostMapping
	public boolean save(@RequestBody SysRoleRequest request) {
		return sysRoleService.save(request);
	}

	/**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	@Override
	@PutMapping
	public boolean update(@RequestBody SysRoleRequest request) {
		return sysRoleService.update(request);
	}

	/**
	 * 移除
	 *
	 * @param id id
	 * @return boolean
	 */
	@Override
	@DeleteMapping("{id}")
	public boolean remove(@PathVariable Long id) {
		return sysRoleService.remove(id);
	}

	/**
	 * 详情
	 *
	 * @param id id
	 * @return vo
	 */
	@Override
	@GetMapping("{id}")
	public SysRoleVO details(@PathVariable("id") Long id) {
		return sysRoleService.details(id);
	}

	@Override
	public boolean savePerms(SysRoleRequest request) {
		return sysRoleService.savePerms(request);
	}
}

